<template>
  <div>
    <el-form ref="mainForm" size="medium" :model="formData" :rules="rules" label-width="100px">
      <el-form-item label="所属地块" prop="name">
        <el-input v-model="formDataClone.fieldAttr.name" placeholder="名称" clearable disabled />
      </el-form-item>
      <el-row>
        <el-col :span="12">
          <el-form-item label="自动决策" prop="autocare">
            <el-switch
              v-model="formDataClone.autocare_mode"
              active-text="打开"
              inactive-text="关闭"
              :active-value="1"
              :inactive-value="0"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-col :span="12">
            <el-form-item label="自动开始日" prop="start_at">
              <el-date-picker
                v-model="formDataClone.started_at"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
                class="full-text"
              />
            </el-form-item>
          </el-col>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="自动暂停" prop="autopause">
            <el-switch
              v-model="formDataClone.autopause"
              active-text="打开"
              inactive-text="关闭"
              :active-value="1"
              :inactive-value="0"
            />
          </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
          <el-form-item label="自动暂停日" prop="pause_at">
            <el-date-picker
              v-model="formData.pause_at"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
              class="full-text"
            />
          </el-form-item>
        </el-col> -->
      </el-row>
      <el-form-item>
        <el-button type="primary" @click="submit('mainForm')">提交</el-button>
        <el-button @click="reset('mainForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { dclassCodeMap } from '@/utils/constant'
import { deepClone } from '@/utils'
import { cropGrowthes } from '@/api/initial'
export default {
  props: {
    formData: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      formDataClone: deepClone(this.formData),
      rules: {

      }
    }
  },
  computed: {
    ...mapGetters(['devices']),
    qxzs() {
      return this.devices.filter(val => {
        return +val.product_type === dclassCodeMap.qxz
      })
    },
    sqzs() {
      return this.devices.filter(val => {
        return +val.product_type === dclassCodeMap.sqz
      })
    }
  },
  methods: {
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const formData = {
            autocare_mode: this.formDataClone.autocare_mode,
            started_at: this.formDataClone.started_at,
            autopause: this.formDataClone.autopause,
            cropGrowthes:[]
          }
          this.$emit('submit', this.formDataClone.id, formData)
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    reset(formName) {
      this.formDataClone = {}
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
